/*
 * Copyright © 2004-2014 chenYuan. All rights reserved.
 * @Website:wwww.jspx.net
 * @Mail:39793751@qq.com
 * @author: chenYuan , 陈原
 * @License: Jspx.net Framework Code is open source (LGPL)，Jspx.net Framework 使用LGPL 开源授权协议发布。
 * @jvm:jdk1.6+  x86/amd64
 *
 */
package com.jspx.sioc.type;

import com.jspx.utils.StringUtil;

/**
 * Created by IntelliJ IDEA.
 * User:chenYuan (mail:39793751@qq.com)
 * Date: 2007-4-4
 * Time: 23:47:16
 */
public class IntegerArrayXmlType extends TypeSerializer
{
    public String getTypeString()
    {
        return "array";
    }

    public Object getTypeObject()
    {
        String[] stringArray = StringUtil.split((String) value, ",");
        int[] result = new int[stringArray.length];
        for (int i = 0; i < stringArray.length; i++)
        {
            result[i] = StringUtil.toInt(stringArray[i]);
        }
        return result;
    }

    /**
     * 返回XML结果
     *
     * @return
     */
    public String getXMLString()
    {
        Integer[] theValue = (Integer[]) value;
        if (theValue == null || theValue.length < 1) return StringUtil.empty;
        StringBuilder sb = new StringBuilder();
        sb.append("<array name=\"").append(name).append("\" class=\"").append("int").append("\">\r\n");
        for (Object o : theValue)
        {
            sb.append("<value>").append(o).append("</value>\r\n");
        }
        sb.append("</array>\r\n");
        return sb.toString();
    }
}